/*必须要有player 模块：这个是必须的默认模块
player  玩家主模块 默认模块
RouteClient 玩家路由模块   默认模块
*/
package tugou

import (
	"net/http"

	"tugou/logs"

	"tugou/web"
	"tugou/websocket"
)

//这是个同步测试
const (
	Default_Module_CHAN_CACHE = 10
	Default_Player_CHAN_CACHE = 10
)

var (
	Func_Perfix_By_Client  = "C"
	Func_Perfix_By_Gate    = "G"
	Func_Perfix_By_Dynamic = "D"
	Func_Perfix_By_Fix     = "F"
)
var ManageModules = manageModules{} //管理模块
var ManagePlayer = managePlayer{}   //管理玩家
var ManageCenter = manageCenter{}   //中心服务器
//var Conf = config{}                 //管理网关
var Route = web.New()
var upgrader = websocket.Upgrader{
	ReadBufferSize:    4096,
	WriteBufferSize:   4096,
	EnableCompression: true,
	CheckOrigin: func(r *http.Request) bool {
		return true
	},
}

func init() {
	logs.Debug("tugou init")
	logs.Debug("初始化Manage--[start]")
	ManageModules.init()
	ManagePlayer.init()
	ManageCenter.init()
	logs.Debug("初始化Manage--[end]")

}
func Run(url string) {

	Route.GET("/ws", func(c *web.Context) {
		count := len(ManagePlayer.run)
		if count >= ManagePlayer.maxCount {
			return
		}
		player := ManagePlayer.creat()
		player.run(player, c, &upgrader)
	})
	logs.Info("开启监听:", url)
	err := http.ListenAndServe(url, Route)
	logs.Info("开启监听:", err)

}
